﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ESAM_Assignment_3
{
    public partial class DeleteComment : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string name = Request.QueryString["Username"];
			if (name != null)
			{
				string username = Session["username"].ToString();
				//int cmdid = Convert.ToInt32(Session["CommentID"]);
				bool query = CommentClass.checkValueQS(name);
				
				if (!IsPostBack)
				{
					int CommentID = Convert.ToInt32(Request.QueryString["CommentID"]);
					lblCommentID.Text = CommentID.ToString();
					CommentClass myComment = CommentClass.GetComment(CommentID);

					if (name == username && myComment.CommentID == CommentID)
					{
						bool status = CommentClass.DeleteComment(CommentID);
						if (status)
						{
							lblStatus.ForeColor = System.Drawing.Color.Blue;
							lblStatus.Text = "Success. Comment has been deleted.";
						}
						else
						{
							lblStatus.ForeColor = System.Drawing.Color.Red;
							lblStatus.Text = "Error! Comment has not been deleted.";
						}
					}
					else
					{
						{
							Response.Redirect("Default.aspx?Username=" + Session["username"]);
						}
					}
				}
			}
			else
			{
				Response.Redirect("Default.aspx");
			}
        }
    }
}